﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Assignment5
{
    public class Order
    {
        private Customer customer;
        public Dictionary<Goods, int> orderedCatalogue;
        private Time time;
        readonly double amount;
        public static int number = 0;
        public int ID;
        //订单构造函数
        public Order() { }
        public Order(Customer c, Dictionary<Goods, int> orderC, Time time)
        {
            customer = c;
            orderedCatalogue = orderC;
            this.time = time;
            amount = CalcAmount(orderC);
            ID = customer.GetHashCode()+time.GetHashCode()+orderC.GetHashCode();
        }

        //计算订单金额
        double CalcAmount(Dictionary<Goods, int> orderC)
        {
            double sum = 0;
            foreach ((Goods g, int i) in orderC)
            {
                double discount = customer.getIsVIP() ? 0.9 : 1.0;
                sum += i * g.getPrice() * discount;
            }
            return sum;
        }

        public double GetAmount() { return amount; }
        public Customer GetCustomer() { return customer; }

        public void setCustomer(Customer c)
        {
            customer = c;
        }
        public void setCatalogue(Dictionary<Goods,int> d)
        {
            orderedCatalogue = d;
        }
        public void setTime(Time t)
        {
            time = t;
        }
        //重写ToString方法，订单简单信息
        public override string ToString()
        {
            return $"Order time: {time}, Customer: {customer.getName()}\r\n" ;
        }

        //重写equals方法
        public override bool Equals(object obj)
        {
            Order order = (Order)obj;
            return order.customer.Equals(customer)&order.time.Equals(time);
        }

        //重写GetHashCode方法
        public override int GetHashCode()
        {
            return time.GetHashCode()+customer.GetHashCode();
        }
    }

}
